/**
 * 
 */
package acmCoder;

import java.awt.Point;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class 买糖果 {
	static class Point implements Comparable<Point>{
		int value;
		int index;
		public Point(int value,int index) {
			this.value=value;
			this.index=index;
		}
		@Override
		public int compareTo(Point o) {//价值大的排在前面
			if(o.value!=this.value)
				return o.value-this.value;
			else {
				return this.index-o.index;//index小的排在前面
			}
		}
	}
	public static int getMax(int v,PriorityQueue<Point> A1List,PriorityQueue<Point> A2List,PriorityQueue<Integer> inIndex) {
		if(A1List.isEmpty()){//只能装A2
			int value=0;
			while (v>=2&&!A2List.isEmpty()) {
				Point point=A2List.poll();
				inIndex.add(point.index);
				value+=point.value;
				v-=2;
			}
			return value;
		}
		if(A2List.isEmpty()){//剩下所有都是A1序列的
			int value=0;
			while (v>=1&&!A1List.isEmpty()) {
				Point point=A1List.poll();
				inIndex.add(point.index);
				value+=point.value;
				v--;
			}
			return value;
		}
		if(v==0)
			return 0;
		if(v==1){//只能装A1
			Point point=A1List.poll();
			inIndex.add(point.index);
			return point.value;
		}
		if(A1List.size()==1){//a1中只有一个，要不要这一个？---v>2,看A1和A2的哪个价值大
			Point point=A1List.peek();
			Point point2=A2List.peek();
			if(point.value>point2.value){
				A1List.poll();
				inIndex.add(point.index);
				return point.value+getMax(v-1, A1List, A2List, inIndex);
			}else {
				A2List.poll();
				inIndex.add(point2.index);
				return  point2.value+getMax(v-2, A1List, A2List, inIndex);
			}
			
		}
		Point a11=A1List.poll();//拿出来
		Point a12=A1List.peek();
		Point a2=A2List.peek();
		if(a2.value>=a11.value+a12.value){//可以选择A2序列的
			A1List.offer(a11);//放回去
			Point point=A2List.poll();
			inIndex.add(point.index);
			return point.value+getMax(v-2,A1List,A2List,inIndex);
		}else{
			A1List.poll();
			inIndex.add(a11.index);
			inIndex.add(a12.index);
			return a11.value+a12.value+getMax(v-2,A1List,A2List,inIndex);
		}
	}
	
	public static void getMax(int[][] p) {
		
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		while (scanner.hasNextInt()) {
			int n=scanner.nextInt();
			int v=scanner.nextInt();
			PriorityQueue<Point> A1List=new PriorityQueue<>();
			PriorityQueue<Point> A2List=new PriorityQueue<>();
			for (int i = 0; i < n; i++) {
				int type=scanner.nextInt();
				Point point=new Point(scanner.nextInt(), i);
				if(type==1){
					A1List.add(point);
				}else {
					A2List.add(point);
				}
			}
			if(v<1){
				System.out.println(0);
				System.out.println("No");
				continue;
			}
			PriorityQueue<Integer> inIndex=new PriorityQueue<>();
			System.out.println(getMax(v, A1List, A2List, inIndex));
			while (!inIndex.isEmpty()) {
				Integer integer=inIndex.poll();
				System.out.print((integer+1)+" ");
			}
			System.out.println();
		}
	}

}
